package com.fengwk.cv4j.ind;

import org.junit.Test;
import org.nd4j.linalg.factory.Nd4j;

import com.fengwk.cv4j.factory.ind.INDViewFactory;
import com.fengwk.cv4j.view.View;
import com.fengwk.cv4j.view.ind.INDArrayWrap;

public class Mean {

    @Test
    public void test() {
        INDViewFactory f = new INDViewFactory();
        View<INDArrayWrap> X = f.of(Nd4j.create(new float[][][]{ 
            {
                {1, 2, 3},
                {4, 5, 6}
            },
            {
                {1, 2, 3},
                {7, 8, 1}
            }
        }));
        
        View<INDArrayWrap> mean_0 = f.mean(X, 0);
        View<INDArrayWrap> mean_1 = f.mean(X, 1);
        View<INDArrayWrap> mean_0_1 = f.mean(X, 1, 0);
        View<INDArrayWrap> mean_1_0 = f.mean(X, 0, 1);
        
        System.out.println("------mean_0------");
        System.out.println(mean_0.compute().arr());
        System.out.println("------mean_1------");
        System.out.println(mean_1.compute().arr());
        System.out.println("------mean_0_1------");
        System.out.println(mean_0_1.compute().arr());
        System.out.println("------mean_1_0------");
        System.out.println(mean_1_0.compute().arr());
        
        System.out.println("------d_mean_0------");
        System.out.println(mean_0.gradient(X).compute().arr());
        System.out.println("------d_mean_1------");
        System.out.println(mean_1.gradient(X).compute().arr());
        System.out.println("------d_mean_0_1------");
        System.out.println(mean_0_1.gradient(X).compute().arr());
        System.out.println("------d_mean_1_0------");
        System.out.println(mean_1_0.gradient(X).compute().arr());
    }
    
}
